﻿using System;
using System.Collections.Generic;
using System.Text;
using MySpiderMgr.Data;
using MySpiderMgr.Domain.Common;
using MySpiderMgr.Domain.Common.Dtos;
using System.Linq;
using System.Linq.Expressions;
using MySpiderMgr.Data.IRepositories.Common;
using MySpiderMgr.Domain.Common.Filters;

namespace MySpiderMgr.Services.Common
{
    public class SequenceService : ISequenceService
    {
        readonly IUnitOfWork _UnitOfWork;
        readonly ISysSequenceRepository _SysSequenceRep;
        public SequenceService(ISysSequenceRepository sequenceRepository, IUnitOfWork unitOfWork)
        {
            this._SysSequenceRep = sequenceRepository;
            this._UnitOfWork = unitOfWork;
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="Filter"></param>
        /// <returns></returns>
        public List<SysSequence> FindSysSequences(FindSysSequenceFilter Filter)
        {
            return _SysSequenceRep.FindSysSequences(Filter);
        }
        /// <summary>
        /// 根据Id查找
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public SysSequence GetById(int Id)
        {
            return _SysSequenceRep.GetById(Id);
        }

        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="dto"></param>
        public void Add(CreateSysSequenceDto dto)
        {
            _SysSequenceRep.Add(SysSequence.Create(dto));
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        public void Modify(ModifySysSequenceDto dto)
        {
            //获取当前对象
            var _Sequence = _SysSequenceRep.GetById(dto.Id);
            _Sequence.Modify(dto);
            _UnitOfWork.BeginTran();
            _SysSequenceRep.Update(_Sequence);
            _UnitOfWork.Commit();
        }
    }
}
